package com.vic.service.impl;
import com.vic.other.SimplePage;
import com.vic.enums.PageSizeEnum;
import com.vic.entity.GoodsInfo;
import com.vic.entity.query.GoodsInfoQuery;
import com.vic.entity.vo.PaginationResultVo;
import com.vic.mapper.GoodsInfoMapper;
import com.vic.service.GoodsInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * @description：商品信息ServiceImpl
 * @date：2023-05-28
 * @author：Vic Ly
 */
@Service("goodsInfoService")
public class GoodsInfoServiceImpl implements GoodsInfoService {
	@Resource
	private GoodsInfoMapper<GoodsInfo,GoodsInfoQuery> goodsInfoMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<GoodsInfo> findListByParam(GoodsInfoQuery query) {
		return this.goodsInfoMapper.selectList(query);
	}
	/**
	 * 根据条件查询数量
	 */
	public Integer findCountByParam(GoodsInfoQuery query) {
		return this.goodsInfoMapper.selectCount(query);
	}
	/**
	 * 分页查询
	 */
	public PaginationResultVo<GoodsInfo> findListByPage(GoodsInfoQuery query) {
		int count = this.findCountByParam(query);
		int pageSize = query.getPageSize()==null ? PageSizeEnum.SIZE15.getSize():query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNum(),count,pageSize);
		query.setSimplePage(page);
		List<GoodsInfo> list = this.findListByParam(query);
		PaginationResultVo<GoodsInfo> result = new PaginationResultVo(count,page.getPageSize(),page.getPageNum(),page.getPageTotal(),list);
		return result;
	}
	/**
	 * 新增
	 */
	public Integer add(GoodsInfo bean) {
		return this.goodsInfoMapper.insert(bean);
	}
	/**
	 * 批量新增
	 */
	public Integer addBatch(List<GoodsInfo> listBean) {
		if(listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.goodsInfoMapper.insertBatch(listBean);
	}
	/**
	 * 批量新增或修改
	 */
	public Integer addOrUpdateBatch(List<GoodsInfo> listBean) {
		if(listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.goodsInfoMapper.insertOrUpdateBatch(listBean);
	}
	/**
	 * 根据Id查询
	 */
	public GoodsInfo getById(Integer id) {
		return this.goodsInfoMapper.selectById(id);
	}
	/**
	 * 根据Id更新
	 */
	public Integer updateById(GoodsInfo bean, Integer id) {
		return this.goodsInfoMapper.updateById(bean,id);
	}
	/**
	 * 根据Id删除
	 */
	public Integer deleteById(Integer id) {
		return this.goodsInfoMapper.deleteById(id);
	}
	/**
	 * 根据GoodsCode查询
	 */
	public GoodsInfo getByGoodsCode(String goodsCode) {
		return this.goodsInfoMapper.selectByGoodsCode(goodsCode);
	}
	/**
	 * 根据GoodsCode更新
	 */
	public Integer updateByGoodsCode(GoodsInfo bean, String goodsCode) {
		return this.goodsInfoMapper.updateByGoodsCode(bean,goodsCode);
	}
	/**
	 * 根据GoodsCode删除
	 */
	public Integer deleteByGoodsCode(String goodsCode) {
		return this.goodsInfoMapper.deleteByGoodsCode(goodsCode);
	}
	/**
	 * 根据GoodsStock查询
	 */
	public GoodsInfo getByGoodsStock(Integer goodsStock) {
		return this.goodsInfoMapper.selectByGoodsStock(goodsStock);
	}
	/**
	 * 根据GoodsStock更新
	 */
	public Integer updateByGoodsStock(GoodsInfo bean, Integer goodsStock) {
		return this.goodsInfoMapper.updateByGoodsStock(bean,goodsStock);
	}
	/**
	 * 根据GoodsStock删除
	 */
	public Integer deleteByGoodsStock(Integer goodsStock) {
		return this.goodsInfoMapper.deleteByGoodsStock(goodsStock);
	}
}